Page({
  data: {
    paperList: [ // 模拟试卷数据
      {
        id: 1,
        title: '党史基础知识测试',
        questionCount: 20,
        participants: 2356,
        difficultyStars: [true, true, false, false, false], // 五颗星难度
        type: '历史类'
      },
      {
        id: 2,
        title: '新时代思想理论考核',
        questionCount: 20,
        participants: 1893,
        difficultyStars: [true, true, true, false, false],
        type: '政治类'
      },
      {
        id: 3,
        title: '革命根据地历史知识竞赛',
        questionCount: 20,
        participants: 1678,
        difficultyStars: [true, true, true, false, false],
        type: '历史类'
      },
      {
        id: 4,
        title: '红色经典文学作品解读',
        questionCount: 15,
        participants: 924,
        difficultyStars: [true, true, false, false, false],
        type: '文学类'
      },
      {
        id: 5,
        title: '红军长征专题挑战赛',
        questionCount: 25,
        participants: 3021,
        difficultyStars: [true, true, true, true, false],
        type: '军事类'
      },
      {
        id: 6,
        title: '革命英雄人物事迹问答',
        questionCount: 20,
        participants: 2455,
        difficultyStars: [true, true, true, false, false],
        type: '人物类'
      },
      {
        id: 7,
        title: '新中国建设成就问答',
        questionCount: 18,
        participants: 1890,
        difficultyStars: [true, true, true, true, false],
        type: '发展类'
      },
      {
        id: 8,
        title: '红色歌曲文化知识竞赛',
        questionCount: 15,
        participants: 1324,
        difficultyStars: [true, true, false, false, false],
        type: '艺术类'
      },
      {
        id: 9,
        title: '改革开放历程知识测试',
        questionCount: 22,
        participants: 2789,
        difficultyStars: [true, true, true, true, true],
        type: '改革类'
      },
      {
        id: 10,
        title: '二十大精神专题考核',
        questionCount: 20,
        participants: 3567,
        difficultyStars: [true, true, true, true, false],
        type: '政策类'
      },
      {
        id: 11,
        title: '红色旅游景点知识竞赛',
        questionCount: 15,
        participants: 987,
        difficultyStars: [true, true, false, false, false],
        type: '旅游类'
      },
      {
        id: 12,
        title: '社会主义核心价值观问答',
        questionCount: 20,
        participants: 4123,
        difficultyStars: [true, true, true, false, false],
        type: '理论类'
      }
    ]
  },

  // 跳转到答题页
  goToExam(e) {
    const id = e.currentTarget.dataset.id
    console.log(id)
    wx.navigateTo({
      url: `/pages/exam/exam?id=${id}`
    })
  },

  // 加载试卷数据（实际开发中应调用API）
  loadPapers() {
    // 示例：从缓存读取
    const cachedData = wx.getStorageSync('paperList')
    if (cachedData) {
      this.setData({ paperList: cachedData })
    } else {
      // 模拟网络请求
      setTimeout(() => {
        wx.setStorageSync('paperList', this.data.paperList)
      }, 500)
    }
  },

  onLoad() {
    this.loadPapers()
  },

  // 下拉刷新
  onPullDownRefresh() {
    this.loadPapers()
    wx.stopPullDownRefresh()
  }
})